<?php

    class Application_Plugin_SetApp extends Zend_Controller_Plugin_Abstract
    {

        protected $_pageArray = array(); //list of controllers and action which can be accessed without login

        public function preDispatch(Zend_Controller_Request_Abstract $request)
        {

            //$request = new Zend_Controller_Request_Http();
            $request = Zend_Controller_Front::getInstance()->getRequest();
            
            $this->setSiteConstants();
            //$this->responsinator($responsiveCheck);
        }

        public function setSiteConstants()
        {
            $db = Zend_Db_Table::getDefaultAdapter();
            $sql = "SELECT config_key, config_value FROM " . CONFIG . " WHERE `config_type` = 'SITE_CONFIG'";
            $result = $db->query($sql)->fetchAll();

            $arr = array();
            foreach ($result as $key => $value)
            {
                define(strtoupper($value["config_key"]), $value["config_value"]);
                $arr[$value['config_key']] = $value['config_value'];
            }

            Zend_Registry::set('SITE_CONFIG', $arr);
            
            
        }

        public function responsinator($responsiveCheck = false)
        {
            $var = Zend_Registry::getInstance();
            
            if($responsiveCheck){
                Zend_Registry::set("device_type", "mobile");
            }
            
            if (!$var->isRegistered('device_type'))
            {
                $detect = new Mobile_Detect;
                $deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'mobile') : 'computer');


                Zend_Registry::set("device_type", $deviceType);
            }
            
        }
        
    }